package br.com.cotec.dao.impl;

import java.io.Serializable;

import javax.persistence.NoResultException;
import javax.persistence.Query;

import br.com.cotec.dao.UsersDao;
import br.com.cotec.model.Users;

public class UsersDaoImpl extends GenericDaoImpl<Users, Serializable> implements UsersDao{

	/**
	 * {@inheritDoc}
	 */
	public Users getByUsers(String userName) {
		Query query = (Query) em.createNamedQuery("Users.findByUserName");
		query.setParameter("userName", userName);
		Users entity;
		try {
			entity = (Users)query.getSingleResult();		
		} catch (NoResultException e) {
			log.warn("Uh oh, Users object with id '"
					+ userName + "' not found...");
			return null;
		}

		return entity;
	}
	
	/**
	 * {@inheritDoc}
	 */
	public boolean exists(String userName) {
		Users login = (Users) getByUsers(userName);
		return login != null;
	}
}